import pygame
from pygame.locals import *
from Widget import *

class Window(Widget):
   """ 
       Base window widget. must be used as a parent for other widgets at the moment.
       TODO: add support for drawing widgets without parents. Maybe some sort of 'blank parent' 
   """
   def __init__(self, rect, title_, font_, drawtop=True):
      Widget.__init__(self)
      self.drawtop = drawtop
      self.titleText = title_
      self.rect = pygame.Rect(rect[0], rect[1], rect[2], rect[3])
      self.title_rect = pygame.Rect
      self.font = pygame.font.Font(font_, 10)
      self.can_drag = True
      self.titleTextSurface = self.font.render(self.titleText, 1, (255,255,255))
      self.titleImage = pygame.image.load("windowTitle.png")
      titleBgWidth = self.rect.w - 2
      titleBgHeight = 20
      self.titleBg = pygame.Surface((titleBgWidth, titleBgHeight))
      numX = 4+(titleBgWidth/100)
      print numX
      tempX = 0
      self.titleBg.blit(self.titleImage, (0,0,100,20))
      while tempX <= numX:
         self.titleBg.blit(self.titleImage, ((100*tempX),0,100,20))
         tempX += 1
         
   def draw(self):
      pygame.draw.rect(self.screen, (61,61,61), self.rect)
      if self.drawtop:
         self.screen.blit(self.titleBg, 
            (  self.rect.x+1, 
               self.rect.y, 
               self.rect.w, 
               10 ))
         self.screen.blit(self.titleTextSurface, 
            (  self.rect.x+6,
               self.rect.y+5,
               self.rect.w-4,
               15))
      for child in self.children:
         child.draw()